<template>
<view class="ac-circle-shadow" :style="{left: circleShadowLeft}" />
<view class="nav-container">
  <view class="oa-navbar flex flex-row">
    <view
      :style="{ width: navCallWidth }"
      v-for="(item, key) in navbarList"
      :key="key"
      @click="setActiveNav(key)"
      :class="[
        'nav-cell flex flex-column align-center justify-center',
        {'is-active': activeNav === key}
      ]"
    >
      <view class="cell-icon-box flex-shrink-0">
        <view :class="['cell-icon__inner', {'is-home': item.home}]">
          <image class="nav-cell-icon" :src="activeNav !== key ? item.icon : item.acIcon"></image>
        </view>
      </view>
      <view v-show="activeNav !== key" class="nav-cell-name">{{ item.name }}</view>
    </view>
  </view>
</view>
</template>

<script setup lang="ts">
import {OaTabBarType} from "@/enum";

defineOptions({ name: 'OaNavbar' })

const props = defineProps({
  activeNav: {
    type: Number,
    default: null,
  }
})
const $emit = defineEmits(['update:activeNav'])

const navCallWidth = computed(() => {
  const len = navbarList?.length || 0
  if (!len) {
    return '100%'
  } else {
    return (100 / len) + '%'
  }
})

function  setActiveNav(key: number) {
  $emit('update:activeNav', key)
}

const circleShadowLeft = computed(() => {
  const idx = navbarList.map(item => item.key).indexOf(props.activeNav);
  const len = navbarList?.length || 0
  if (idx !== -1) {
    return `calc(40rpx + (100% - 80rpx) / ${len * 2} * (${idx} * 2 + 1) - 52rpx)`
  }
})

import img1 from '@/static/tabbar/pm/home.svg'
import img2 from '@/static/tabbar/pm/home-ac.svg'
import img3 from '@/static/tabbar/pm/proposed.svg'
import img4 from '@/static/tabbar/pm/proposed-ac.svg'
import img5 from '@/static/tabbar/pm/todo.svg'
import img6 from '@/static/tabbar/pm/todo-ac.svg'
import img7 from '@/static/tabbar/pm/my.svg'
import img8 from '@/static/tabbar/pm/my-ac.svg'
const navbarList = [
  {
    name: '首页',
    icon: img1,
    acIcon: img2,
    home: true,
    key: OaTabBarType.HOME
  },
  {
    name: '待办',
    icon: img5,
    acIcon: img6,
    home: false,
    key: OaTabBarType.TODO
  },
  {
    name: '拟办',
    icon: img3,
    acIcon: img4,
    home: false,
    key: OaTabBarType.PROPOSED
  },
  {
    name: '我的',
    icon: img7,
    acIcon: img8,
    home: false,
    key: OaTabBarType.MY
  }
]
</script>

<style scoped lang="scss">
.ac-circle-shadow {
  transition: all 0.3s;
  width: 104rpx;
  height: 104rpx;
  position: absolute;
  bottom:40rpx;
  background-color: #fff;
  z-index: -1;
  border-radius: 50%;
  box-shadow: 0px 0 8px 0px rgba(0, 0, 0, 0.3)
}

.oa-navbar {
  height: 100%;

  .nav-cell.is-active {
    top: -35rpx;

    .cell-icon-box {
      width: 104rpx;
      height: 104rpx;
      border-radius: 50%;
      padding: 10rpx;
      box-sizing: border-box;
      //box-shadow: 0px 0 8px 0px rgba(0, 0, 0, 0.3);

      .is-home {
        background-color: var(--primary-color);
      }

      .cell-icon__inner {
        width: 100%;
        height: 100%;
        border-radius: 50%;
        padding: 15rpx;
        box-sizing: border-box;

        .nav-cell-icon {
          width: 100%;
          height: 100%;
        }
      }
    }

    .nav-cell-name {
      color: var(--primary-color)
    }
  }

  .nav-cell {
    height: 100%;
    transition: all 0.3s;
    position: relative;
    top: 0;

    .cell-icon-box {
      background-color: #fff;
    }

    .cell-icon-box,.cell-icon__inner {
      width: 44rpx;
      height: 44rpx;

      .nav-cell-icon {
        width: 100%;
        height: 100%;
      }
    }

    .nav-cell-name {
      margin-top: 8rpx;
      font-size: 13px;
      font-weight: normal;
      line-height: normal;
      letter-spacing: 0em;
      color: #333333;
    }
  }
}
</style>
